#!/bin/bash
cleanup_environment() {
    for i in {1..10}; do
        vm_name="vm$i"
        # 检查虚拟机是否存在
        if virsh list --all | grep -q "$vm_name"; then
            # 销毁虚拟机，禁止回显
            virsh destroy "$vm_name" >/dev/null 2>&1 &
            sleep 5
            # 移除虚拟机定义，禁止回显
            virsh undefine "$vm_name" --nvram >/dev/null 2>&1 &
            sleep 5
        fi
    done
    echo "环境已清理。"
}


get_vm_ip() {
    local vm_name="$1"
    local ip_address=$(virsh domifaddr "$vm_name" | grep -Eo "([0-9]{1,3}[\.]){3}[0-9]{1,3}") 
    echo "$ip_address"
}

check_and_ping() {
    local ip=$1
    if ping -c 4 $ip ; then
        echo ""
    else
        echo "$1 中的IP无法ping通！"
        return 1
    fi
}

# 配置无密码 SSH 登录
if [ -s "../passwd.txt" ]; then
    password=$(<"../passwd.txt")
fi



